<!DOCTYPE html>
<html lang="zh_cn">
<head>
          <title>来玩魔王的咚</title>
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta charset="utf-8" />
        <!-- twitter card metadata -->
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="/images/mowang.png">
<meta name="twitter:site" content="">
<meta name="twitter:title" content="SmokePing 安装配置">
<meta name="twitter:description" content="<p>yum安装EPEL源的Smokeping；编译安装新版本的SmokePing；安装探针：fping，echoping，tcpping；配置：配置文件说明，配置监控节点，添加中文支持</p>">
        <!-- OG Tags -->
<meta property="og:url" content="/smokeping-how-to.html"/>
<meta property="og:title" content="来玩魔王的咚 | SmokePing 安装配置" />
<meta property="og:description" content="<p>yum安装EPEL源的Smokeping；编译安装新版本的SmokePing；安装探针：fping，echoping，tcpping；配置：配置文件说明，配置监控节点，添加中文支持</p>" />
        <!-- favicon -->
        <link rel="icon" type="image/png" href="/images/mowang.png">
        <!-- moment.js for date formatting -->
        <script src="/theme/js/moment.js"></script>
        <!-- css -->
        <link rel="stylesheet" type="text/css" href="/theme/css/main.css" />
        <!-- 左边的menu，如果页面高度不够，就跟着滚动，否则文章分类显示不全 -->
        <link rel="stylesheet" type="text/css" href="/theme/css/mycss/menu.css" />
		<script>
			
                /*! grunt-grunticon Stylesheet Loader - v2.1.2 | https://github.com/filamentgroup/grunticon | (c) 2015 Scott Jehl, Filament Group, Inc. | MIT license. */
    
    (function(e){function t(t,n,r,o){"use strict";function a(){for(var e,n=0;u.length>n;n++)u[n].href&&u[n].href.indexOf(t)>-1&&(e=!0);e?i.media=r||"all":setTimeout(a)}var i=e.document.createElement("link"),l=n||e.document.getElementsByTagName("script")[0],u=e.document.styleSheets;return i.rel="stylesheet",i.href=t,i.media="only x",i.onload=o||null,l.parentNode.insertBefore(i,l),a(),i}var n=function(r,o){"use strict";if(r&&3===r.length){var a=e.navigator,i=e.Image,l=!(!document.createElementNS||!document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect||!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")||e.opera&&-1===a.userAgent.indexOf("Chrome")||-1!==a.userAgent.indexOf("Series40")),u=new i;u.onerror=function(){n.method="png",n.href=r[2],t(r[2])},u.onload=function(){var e=1===u.width&&1===u.height,a=r[e&&l?0:e?1:2];n.method=e&&l?"svg":e?"datapng":"png",n.href=a,t(a,null,null,o)},u.src="",document.documentElement.className+=" grunticon"}};n.loadCSS=t,e.grunticon=n})(this);(function(e,t){"use strict";var n=t.document,r="grunticon:",o=function(e){if(n.attachEvent?"complete"===n.readyState:"loading"!==n.readyState)e();else{var t=!1;n.addEventListener("readystatechange",function(){t||(t=!0,e())},!1)}},a=function(e){return t.document.querySelector('link[href$="'+e+'"]')},c=function(e){var t,n,o,a,c,i,u={};if(t=e.sheet,!t)return u;n=t.cssRules?t.cssRules:t.rules;for(var l=0;n.length>l;l++)o=n[l].cssText,a=r+n[l].selectorText,c=o.split(");")[0].match(/US\-ASCII\,([^"']+)/),c&&c[1]&&(i=decodeURIComponent(c[1]),u[a]=i);return u},i=function(e){var t,o,a;o="data-grunticon-embed";for(var c in e)if(a=c.slice(r.length),t=n.querySelectorAll(a+"["+o+"]"),t.length)for(var i=0;t.length>i;i++)t[i].innerHTML=e[c],t[i].style.backgroundImage="none",t[i].removeAttribute(o);return t},u=function(t){"svg"===e.method&&o(function(){i(c(a(e.href))),"function"==typeof t&&t()})};e.embedIcons=i,e.getCSS=a,e.getIcons=c,e.ready=o,e.svgLoadedCallback=u,e.embedSVG=u})(grunticon,this);
                
                grunticon(["/theme/css/icons.data.svg.css", "/theme/css/icons.data.png.css", "/theme/css/icons.fallback.css"]);
            </script>
        <noscript><link href="/theme/css/icons.fallback.css" rel="stylesheet"></noscript>
        <!-- menu toggle javascript -->
        <script type="text/javascript">
            document.addEventListener("DOMContentLoaded", initMenu);
            
            function initMenu(){
                var menu = document.getElementById("menu");
                var menulink = document.getElementById("menu-link");
                menulink.addEventListener("click", function toggleMenu(){
                        window.event.preventDefault();
                        menulink.classList.toggle('active');
                        menu.classList.toggle('active');              
                    });
            };
        </script>
        <!-- 不蒜子 -->
        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    <meta name="description" content="<p>yum安装EPEL源的Smokeping；编译安装新版本的SmokePing；安装探针：fping，echoping，tcpping；配置：配置文件说明，配置监控节点，添加中文支持</p>" />

    <meta name="tags" content="监控" />
    <meta name="tags" content="fping" />
  <!-- 替换部分base的样式，看文章时，要再宽一点，右边有很多空间可以撑开 -->
  <link rel="stylesheet" type="text/css" href="/theme/css/mycss/article.css" />

</head>
<body>
    <div role="banner" id="masthead">
        <header>
            <a href="/"><img src="/images/mowang.png" alt="McManus Logo"></a>
                <h1>来玩魔王的咚@骑士救兵</h1>
            <a href="#menu" id="menu-link">more stuff</a>
            <nav id="menu">
                <ul>
                        <li><a href="/tags">tags</a></li>
                            <li><a href="/category/cloud.html">Cloud</a></li>
                            <li><a href="/category/docker.html">Docker</a></li>
                            <li><a href="/category/go.html">Go</a></li>
                            <li class="active"><a href="/category/linux.html">Linux</a></li>
                            <li><a href="/category/python.html">Python</a></li>
                            <li><a href="/category/xue-xi-bi-ji.html">学习笔记</a></li>
                            <li><a href="/category/yun-wei-zi-dong-hua.html">运维自动化</a></li>
                </ul>
            </nav>
        </header>
    </div>
        <div class="page" role="main">
  <div class="article" role="article">
    <article>
        <footer>
            <a name="top"></a>
            <p>
              <time datetime=" 2020-11-24 13:30:00+08:00">
                <script>document.write(moment('2020-11-24 13:30:00+08:00').format('LL'));</script>
              </time>
              ~
              <time datetime=" 2020-11-24 13:30:00+08:00">
                <script>document.write(moment('2020-11-28 15:00:00+08:00').format('LL'));</script>
              </time>
            </p>
        </footer>
        <header>
          <h2>
            SmokePing 安装配置
          </h2>
        </header>
      <div class="content">
         <div class="toc">
<ul>
<li><a href="#yum-an-zhuang">yum 安装</a><ul>
<li><a href="#smokeping-she-zhi">SmokePing 设置</a></li>
<li><a href="#web-she-zhi">Web 设置</a></li>
</ul>
</li>
<li><a href="#an-zhuang-tan-zhen">安装探针</a><ul>
<li><a href="#bian-yi-an-zhuang-fping">编译安装 FPing</a></li>
<li><a href="#bian-yi-an-zhuang-echoping">编译安装 EchoPing</a></li>
<li><a href="#an-zhuang-tcpping">安装 tcpping</a></li>
</ul>
</li>
<li><a href="#bian-yi-an-zhuang_1">编译安装</a><ul>
<li><a href="#smokeping-zhu-fu-wu">SmokePing主服务</a></li>
<li><a href="#pei-zhi-zhu-fu-wu">配置主服务</a></li>
<li><a href="#pei-zhi-web">配置Web</a></li>
<li><a href="#xiao-jie-pei-zhi-bu-shu">小结：配置部署</a></li>
</ul>
</li>
<li><a href="#tong-yong-she-zhi">通用设置</a><ul>
<li><a href="#pei-zhi-wen-jian-shuo-ming">配置文件说明</a></li>
<li><a href="#pei-zhi-targets">配置Targets</a></li>
<li><a href="#tian-jia-zhong-wen-zhi-chi">添加中文支持</a></li>
</ul>
</li>
</ul>
</div>
<p>SmokePing主要用于监视网络性能，包括常规的ping、www服务器性能、DNS查询性能、SSH性能等。底层也是用RRDtool做支持，特点是绘制图非常漂亮，网络丢包和延迟用颜色和阴影来标示，支持将多张图叠放在一起，其作者还开发了MRTG和RRDtll等工具。  </p>
<p>网站：<a href="https://oss.oetiker.ch/smokeping/">https://oss.oetiker.ch/smokeping/</a> 。<br>
中文：<a href="https://wiki.archlinux.org/index.php/Smokeping_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)">https://wiki.archlinux.org/index.php/Smokeping_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)</a> 。  </p>
<p>章节结构：</p>
<ol>
<li>在EPEL源里有2.6.10的旧版，直接yum就完成安装。</li>
<li>探针：支持很多探针，有些需要编译安装</li>
<li>目前最新的版本是2.7.3，再看看如何编辑安装新版使用。</li>
<li>还有一些通用的设置，放在最后的章节一起讲。</li>
</ol>
<p>另外，先把系统的Selinux关了，不考虑这个问题。防火墙还是继续开着。  </p>
<h3 id="yum-an-zhuang"><a class="toclink" href="#yum-an-zhuang">yum 安装</a></h3>
<p>虽然EPEL源的版本较旧，但是安装方便，直接就能使用。</p>
<p><strong>安装阿里的EPEL源</strong><br>
下面两条命令，任意一条就可以。有些系统默认没有安装wget命令：</p>
<div class="highlight"><pre><span></span><code>wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
</code></pre></div>

<p>然后直接yum安装：</p>
<div class="highlight"><pre><span></span><code>yum install smokeping
<span class="c1"># 安装  1 软件包 (+118 依赖软件包)</span>
</code></pre></div>

<p>一共119个软件包一次搞定。  </p>
<h4 id="smokeping-she-zhi"><a class="toclink" href="#smokeping-she-zhi">SmokePing 设置</a></h4>
<p>SmokePing不用任何设置，直接就能启动看效果。默认就加好了3个节点做fping监控。<br>
配置文件是<code>/etc/smokeping/config</code>，下面是配置文件中监控主机的设置：</p>
<div class="highlight"><pre><span></span><code>+ Ping

menu = Fedora
title = Fedora Pings

++ FedoraprojectOrg

menu = fedoraproject.org
title = Fedora Webserver
host = fedoraproject.org

++ DocsFedoraprojectOrg

menu = docs.fedoraproject.org
title = Fedora Docs Webserver
host = docs.fedoraproject.org

++ PlanetFedora

menu = planet.fedoraproject.org
title = Planet Fedora
host = planet.fedoraproject.org

#
# Lots of more options are available, please have a look in the included documentation.
#
</code></pre></div>

<p>这里默认加了3个节点的fping监控，可以改成自己的，也可以继续加节点。<br>
下面注释的说明，建议included专门的配置文件，添加监控节点。  </p>
<p>配置文件调整完之后，可以用下面的命令，方便验证。<br>
启动、停止、重启、重载：</p>
<div class="highlight"><pre><span></span><code>smokeping
<span class="nb">kill</span> <span class="k">$(</span>cat /var/run/smokeping/smokeping.pid<span class="k">)</span>
smokeping --restart
--reload
</code></pre></div>

<p>居然没有stop，只能用kill来了关闭。  </p>
<p>最后还是使用服务启动：</p>
<div class="highlight"><pre><span></span><code>systemctl <span class="nb">enable</span> smokeping
systemctl start smokeping
</code></pre></div>

<h4 id="web-she-zhi"><a class="toclink" href="#web-she-zhi">Web 设置</a></h4>
<p>默认的Web服务也不用调整，直接启动httpd即可，但是只能本机访问。按下面的进行调整。  </p>
<p>使用Apache提供Web服务，默认配置如下：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>cat /etc/httpd/conf.d/smokeping.conf
<span class="go">&lt;Directory &quot;/usr/share/smokeping&quot; &gt;</span>
<span class="go">  Require local</span>
<span class="gp">  # </span>Require ip <span class="m">2</span>.5.6.8
<span class="gp">  # </span>Require host example.org
<span class="go">&lt;/Directory&gt;</span>

<span class="go">&lt;Directory &quot;/var/lib/smokeping&quot; &gt;</span>
<span class="go">  Require local</span>
<span class="gp">  # </span>Require ip <span class="m">2</span>.5.6.8
<span class="gp">  # </span>Require host example.org
<span class="go">&lt;/Directory&gt;</span>

<span class="gp"># </span>.fcgi : smokeping by mod_fcgid aka fastcgi
<span class="gp"># </span>_cgi  : plain old fashion cgi
<span class="go">ScriptAlias /smokeping/sm.cgi  /usr/share/smokeping/cgi/smokeping.fcgi</span>
<span class="gp">#</span>ScriptAlias /smokeping/sm.cgi  /usr/share/smokeping/cgi/smokeping_cgi

<span class="go">Alias       /smokeping/images  /var/lib/smokeping/images</span>
<span class="go">Alias       /smokeping         /usr/share/smokeping/htdocs</span>
<span class="gp">$ </span>
</code></pre></div>

<p>两个文件夹的权限都是<code>Require local</code>，这样外部的机器是无法访问的。<br>
都改成<code>Require all granted</code>，然后重启httpd服务即可。  </p>
<p>防火墙：</p>
<div class="highlight"><pre><span></span><code>firewall-cmd --permanent --add-service<span class="o">=</span>http
firewall-cmd --permanent --add-service<span class="o">=</span>https
firewall-cmd --reload
</code></pre></div>

<p>启动服务：</p>
<div class="highlight"><pre><span></span><code>systemctl <span class="nb">enable</span> httpd
systemctl start httpd
</code></pre></div>

<p>使用下面的url访问：</p>
<div class="highlight"><pre><span></span><code>http://127.0.0.1/smokeping/sm.cgi
</code></pre></div>

<h5 id="tian-jia-url-tiao-zhuan"><a class="toclink" href="#tian-jia-url-tiao-zhuan">添加url跳转</a></h5>
<p>上面那串地址用起来不好记，在http的设置里再加一个重定向的跳转：</p>
<div class="highlight"><pre><span></span><code><span class="nb">echo</span> <span class="s1">&#39;RedirectMatch permanent &quot;^/smokeping/?$&quot; /smokeping/sm.cgi&#39;</span> <span class="se">\</span>
&gt;&gt; /etc/httpd/conf.d/smokeping.conf 
</code></pre></div>

<p>启动httpd服务生效。使用<code>/smokeping</code>或<code>/smokeping/</code>都会跳转。  </p>
<h3 id="an-zhuang-tan-zhen"><a class="toclink" href="#an-zhuang-tan-zhen">安装探针</a></h3>
<p>主要的探针有一下这些：</p>
<table>
<thead>
<tr>
<th align="left">探针</th>
<th align="left">命令</th>
<th align="left">软件包</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">FPing</td>
<td align="left">fping</td>
<td align="left">fping</td>
</tr>
<tr>
<td align="left">EchoPing</td>
<td align="left">echoping</td>
<td align="left">echoping</td>
</tr>
<tr>
<td align="left">Curl</td>
<td align="left">curl</td>
<td align="left">curl</td>
</tr>
<tr>
<td align="left">DNS</td>
<td align="left">dig</td>
<td align="left">bind-utils</td>
</tr>
<tr>
<td align="left">SSH</td>
<td align="left">ssh-keyscan</td>
<td align="left">openssh-clients</td>
</tr>
</tbody>
</table>
<p>探针都是可选的，但是fping是最基本的功能，基本是必须的了。<br>
更多的探针见官网：<a href="https://oss.oetiker.ch/smokeping/probe/index.en.html">https://oss.oetiker.ch/smokeping/probe/index.en.html</a> 。  </p>
<h4 id="bian-yi-an-zhuang-fping"><a class="toclink" href="#bian-yi-an-zhuang-fping">编译安装 FPing</a></h4>
<p>SmokePing 2.7.2 之后需要 fping4.0 以上，EPEL源里的版本旧了。需要编译安装。<br>
下载4.4版本，然后编译安装：</p>
<div class="highlight"><pre><span></span><code>wget http://www.fping.org/dist/fping-4.4.tar.gz
tar -xzf fping-4.4.tar.gz
<span class="nb">cd</span> fping-4.4
./configure
make
make install
</code></pre></div>

<p>验证使用一下：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>fping --version
<span class="go">fping: Version 4.4</span>
<span class="go">fping: comments to david@schweikert.ch</span>
<span class="gp">$ </span>fping <span class="m">223</span>.5.5.5
<span class="go">223.5.5.5 is alive</span>
<span class="gp">$ </span>fping -c3 <span class="m">8</span>.8.8.8
<span class="go">8.8.8.8 : [0], 84 bytes, 235 ms (235 avg, 0% loss)</span>
<span class="go">8.8.8.8 : [1], 84 bytes, 235 ms (235 avg, 0% loss)</span>
<span class="go">8.8.8.8 : [2], 84 bytes, 235 ms (235 avg, 0% loss)</span>

<span class="go">8.8.8.8 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 235/235/235</span>
<span class="gp">$ </span>fping -C5 <span class="m">8</span>.8.8.8
<span class="go">8.8.8.8 : [0], 84 bytes, 235 ms (235 avg, 0% loss)</span>
<span class="go">8.8.8.8 : [1], 84 bytes, 235 ms (235 avg, 0% loss)</span>
<span class="go">8.8.8.8 : [2], 84 bytes, 235 ms (235 avg, 0% loss)</span>
<span class="go">8.8.8.8 : [3], 84 bytes, 235 ms (235 avg, 0% loss)</span>
<span class="go">8.8.8.8 : [4], 84 bytes, 235 ms (235 avg, 0% loss)</span>

<span class="go">8.8.8.8 : 235.36 235.47 235.58 235.53 235.50</span>
<span class="gp">$ </span>
</code></pre></div>

<h4 id="bian-yi-an-zhuang-echoping"><a class="toclink" href="#bian-yi-an-zhuang-echoping">编译安装 EchoPing</a></h4>
<p>这个项目已经基本不维护了，不过还是有点用的，也是SmokePing主要支持的探针之一。  </p>
<h5 id="gong-ju-jie-shao"><a class="toclink" href="#gong-ju-jie-shao">工具介绍</a></h5>
<p>有个RFC862 回声协议（RFC 862 Echo Protocol），在TCP和UDP的7端口上定义的回声服务。工具的名字就是这个意思。<br>
默认的功能也是向服务器的默认TCP的7端口请求回声服务，另外还有discard（丢弃）服务，端口9，以及chargen（字符发生器）服务，端口19。这些现在都没什么用。<br>
不过，还能使用其他协议，比如http，借助插件还有DNS。可以获取响应时间来监控网络性能。<br>
所以，这是一个基于协议的响应时间监控工具。请求对端服务器的某个服务，获取整个过程的时间。不过主要的协议也就http了。  </p>
<h5 id="bian-yi-an-zhuang"><a class="toclink" href="#bian-yi-an-zhuang">编译安装</a></h5>
<p>安装如下，需要加一些开发包否则安装好功能不全：</p>
<div class="highlight"><pre><span></span><code>wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz
tar -xzf echoping-6.0.2.tar.gz
<span class="nb">cd</span> echoping-6.0.2
yum install popt-devel libidn-devel openssl-devel
./configure --with-ssl --enable-icp
make
make install
</code></pre></div>

<p>验证一下：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>echoping -V
<span class="go">echoping 6.0.2 compiled with cc on SmokePing (x86_64-unknown-linux-gnu)</span>
<span class="go"> at 2020-11-24 with options:</span>

<span class="go">HTTP: enabled</span>
<span class="go">ICP: enabled</span>
<span class="go">OPENSSL: enabled</span>
<span class="go">GNUTLS: disabled </span>
<span class="go">SMTP: enabled</span>
<span class="go">LIBIDN: enabled</span>
<span class="go">TOS: enabled</span>
<span class="go">PRIORITY: enabled</span>

<span class="go">Plugins are searched in /usr/local/lib/echoping.</span>
<span class="gp">$ </span>
</code></pre></div>

<p>这里看功能都全了，这里的OPENSSL和GNUTLS是只能二选一的。  </p>
<p>再看下插件：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>ls /usr/local/lib/echoping/*.a
<span class="go">/usr/local/lib/echoping/dns.a  /usr/local/lib/echoping/random.a  /usr/local/lib/echoping/whois.a</span>
<span class="gp">$ </span>
</code></pre></div>

<h5 id="shi-yong-shuo-ming"><a class="toclink" href="#shi-yong-shuo-ming">使用说明</a></h5>
<p>有man文档：</p>
<div class="highlight"><pre><span></span><code>man echoping
</code></pre></div>

<p>看后面的EXAMPLES，有一些使用的示例。  </p>
<p>命令本身和插件的--help说明：</p>
<div class="highlight"><pre><span></span><code>echoping --help
echoping -m dns localhost --help
echoping -m whois localhost --help
</code></pre></div>

<h5 id="shi-yong-shi-li"><a class="toclink" href="#shi-yong-shi-li">使用示例</a></h5>
<p>请求http和https服务：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>echoping -n <span class="m">3</span> -h / www.baidu.com
<span class="go">Elapsed time: 0.042723 seconds</span>
<span class="go">Elapsed time: 0.047301 seconds</span>
<span class="go">Elapsed time: 0.043823 seconds</span>
<span class="go">---</span>
<span class="go">Minimum time: 0.042723 seconds (5992 bytes per sec.)</span>
<span class="go">Maximum time: 0.047301 seconds (5412 bytes per sec.)</span>
<span class="go">Average time: 0.044615 seconds (5738 bytes per sec.)</span>
<span class="go">Standard deviation: 0.001951</span>
<span class="go">Median time: 0.043823 seconds (5842 bytes per sec.)</span>
<span class="gp">$ </span>echoping -n <span class="m">3</span> -C -h / www.baidu.com:443
<span class="go">Elapsed time: 0.048664 seconds</span>
<span class="go">Elapsed time: 0.051455 seconds</span>
<span class="go">Elapsed time: 0.052089 seconds</span>
<span class="go">---</span>
<span class="go">Minimum time: 0.048664 seconds (5261 bytes per sec.)</span>
<span class="go">Maximum time: 0.052089 seconds (4915 bytes per sec.)</span>
<span class="go">Average time: 0.050736 seconds (5046 bytes per sec.)</span>
<span class="go">Standard deviation: 0.001487</span>
<span class="go">Median time: 0.051455 seconds (4975 bytes per sec.)</span>
<span class="gp">$ </span>
</code></pre></div>

<p>请求DNS服务：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>echoping -n <span class="m">3</span> -m dns <span class="m">223</span>.5.5.5 baidu.com
<span class="go">Elapsed time: 0.005394 seconds</span>
<span class="go">Elapsed time: 0.005829 seconds</span>
<span class="go">Elapsed time: 0.006412 seconds</span>
<span class="go">---</span>
<span class="go">Minimum time: 0.005394 seconds (47460 bytes per sec.)</span>
<span class="go">Maximum time: 0.006412 seconds (39925 bytes per sec.)</span>
<span class="go">Average time: 0.005878 seconds (43552 bytes per sec.)</span>
<span class="go">Standard deviation: 0.000417</span>
<span class="go">Median time: 0.005829 seconds (43918 bytes per sec.)</span>
<span class="gp">$ </span>
</code></pre></div>

<p>whois插件的使用：</p>
<div class="highlight"><pre><span></span><code>echoping -m whois whois.internic.net -d shuxun.net
echoping -m whois whois.paycenter.com.cn -d shuxun.net
echoping -m whois ewhois.cnnic.cn -d baid.cn
</code></pre></div>

<p>返回结果太长了，就不贴了。每台whois服务器都有自己负责的查询内容，比如<code>ewhois.cnnic.cn</code>只能查 .cn 的域名。  </p>
<p>random插件：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>echoping -n <span class="m">3</span> -m random localhost
<span class="go">Elapsed time: 0.028333 seconds</span>
<span class="go">Elapsed time: 0.824902 seconds</span>
<span class="go">Elapsed time: 0.545539 seconds</span>
<span class="go">---</span>
<span class="go">Minimum time: 0.028333 seconds (9035 bytes per sec.)</span>
<span class="go">Maximum time: 0.824902 seconds (310 bytes per sec.)</span>
<span class="go">Average time: 0.466258 seconds (549 bytes per sec.)</span>
<span class="go">Standard deviation: 0.329994</span>
<span class="go">Median time: 0.545539 seconds (469 bytes per sec.)</span>
<span class="gp">$ </span>
</code></pre></div>

<p>这个插件不会真正去测试性能，而是随机生成时间sleep。只是用来测试和验证的，另外也作为制作插件的示例可以参考。  </p>
<h4 id="an-zhuang-tcpping"><a class="toclink" href="#an-zhuang-tcpping">安装 tcpping</a></h4>
<p>在SmokePing中使用：<a href="https://oss.oetiker.ch/smokeping/probe/TCPPing.en.html">https://oss.oetiker.ch/smokeping/probe/TCPPing.en.html</a> 。<br>
安装：<a href="https://github.com/deajan/tcpping">https://github.com/deajan/tcpping</a> 。  </p>
<p>安装步骤：</p>
<div class="highlight"><pre><span></span><code>wget -O /usr/bin/tcpping https://raw.githubusercontent.com/deajan/tcpping/master/tcpping
chmod <span class="m">755</span> /usr/bin/tcpping
</code></pre></div>

<p>项目直接就一个可执行文件，下载然后设置可执行权限后就可以用了。  </p>
<h5 id="yu-ming-wen-ti"><a class="toclink" href="#yu-ming-wen-ti">域名问题</a></h5>
<p>这里的域名<code>raw.githubusercontent.com</code>被DNS服务器污染了：</p>
<div class="highlight"><pre><span></span><code>&gt; server 202.96.209.5
默认服务器:  ns-px.online.sh.cn
Address:  202.96.209.5

&gt; raw.githubusercontent.com
服务器:  ns-px.online.sh.cn
Address:  202.96.209.5

非权威应答:
名称:    raw.githubusercontent.com
Addresses:  ::
          0.0.0.0

&gt; server 223.5.5.5
默认服务器:  public1.alidns.com
Address:  223.5.5.5

&gt; raw.githubusercontent.com
服务器:  public1.alidns.com
Address:  223.5.5.5

非权威应答:
名称:    github.map.fastly.net
Address:  151.101.76.133
Aliases:  raw.githubusercontent.com

&gt; 
</code></pre></div>

<p>换一个靠谱的DNS或者编辑一下本地的hosts文件来解决。  </p>
<h5 id="yi-lai-wen-ti"><a class="toclink" href="#yi-lai-wen-ti">依赖问题</a></h5>
<p>这个工具依赖traceroute，会给提示：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>tcpping
<span class="go">/usr/bin/tcpping: line 160: type: traceroute: not found</span>
<span class="go">traceroute binary not found. Please install it first</span>
<span class="gp">$ </span>
</code></pre></div>

<p>没有装的话，先用yum安装好：</p>
<div class="highlight"><pre><span></span><code>yum provides traceroute  <span class="c1"># 找一下具体是哪个包</span>
yum install traceroute   <span class="c1"># 直接yum安装</span>
</code></pre></div>

<h3 id="bian-yi-an-zhuang_1"><a class="toclink" href="#bian-yi-an-zhuang_1">编译安装</a></h3>
<p>新版需要编译安装。<br>
先了解下SmokePing整个系统的组成部分：</p>
<ul>
<li>Web服务：网页可视化查看</li>
<li>SmokePing主服务：执行检测任务</li>
<li>探针：具体获取检测数据的工具</li>
<li>rrdtool：数据库</li>
</ul>
<p>探针上面已经介绍过了。  </p>
<p>rrdtool的版本有要求：RRDtool 1.2.x or later<br>
不过yum源的版本也符合了，直接yum安装：</p>
<div class="highlight"><pre><span></span><code>yum install rrdtool perl-rrdtool openssl-devel
</code></pre></div>

<p>用Apache提供Web服务：</p>
<div class="highlight"><pre><span></span><code>yum install httpd
</code></pre></div>

<p>另外，SmokePing是fcgi程序，还需要为Apache添加mod_fcgid，也是yum安装：</p>
<div class="highlight"><pre><span></span><code>yum install mod_fcgid
</code></pre></div>

<h4 id="smokeping-zhu-fu-wu"><a class="toclink" href="#smokeping-zhu-fu-wu">SmokePing主服务</a></h4>
<p>这个项目是用Perl语言实现的，需要Perl 5.10.1 or later。直接yum安装：</p>
<div class="highlight"><pre><span></span><code>yum install perl-core
</code></pre></div>

<p>下载然后编译安装：</p>
<div class="highlight"><pre><span></span><code>wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.3.tar.gz
tar -xzf smokeping-2.7.3.tar.gz
<span class="nb">cd</span> smokeping-2.7.3
./configure --prefix<span class="o">=</span>/opt/smokeping
</code></pre></div>

<p>这里的<code>--prefix=/opt/smokeping</code>选项是照着官网写的。<br>
到这里先停一下，看下configure之后的输出：</p>
<div class="highlight"><pre><span></span><code>** Ready to install Smokeping ******************************

   Settings:

     PERL5LIB = not set
     PERL = /usr/bin/perl

   The Smokeping Makefiles use GNU make functionality.
   Continue installation with

     /usr/bin/gmake install
</code></pre></div>

<p>这里的<code>PERL5LIB = not set</code>表示没有指定PERL5LIB。需要手动指一下，用环境变量：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span><span class="nv">PERL5LIB</span><span class="o">=</span>/usr/lib64/perl5/  ./configure --prefix<span class="o">=</span>/opt/smokeping

<span class="go">** Ready to install Smokeping ******************************</span>

<span class="go">   Settings:</span>

<span class="go">     PERL5LIB = /usr/lib64/perl5/</span>
<span class="go">     PERL = /usr/bin/perl</span>

<span class="go">   The Smokeping Makefiles use GNU make functionality.</span>
<span class="go">   Continue installation with</span>

<span class="go">     /usr/bin/gmake install</span>

<span class="gp">$ </span>
</code></pre></div>

<p>这下有了，然后这里给了命令，就这提示给的，而不是<code>make &amp;&amp; make install</code>。<br>
最后一步完成安装：</p>
<div class="highlight"><pre><span></span><code>/usr/bin/gmake install
</code></pre></div>

<p>查看版本信息：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>/opt/smokeping/bin/smokeping --version
<span class="go">2.007003</span>
<span class="gp">$ </span>
</code></pre></div>

<p>现在还无法启动，许多配置文件需要调整。未编辑的文件的扩展名为.dist，需要把这些后缀都去掉。具体看下一节。<br>
完整的配置文件修改，见这章节最后一小节<strong>小结：配置部署</strong>。  </p>
<h4 id="pei-zhi-zhu-fu-wu"><a class="toclink" href="#pei-zhi-zhu-fu-wu">配置主服务</a></h4>
<p>用下面的命令可以在前端启动SmokePing：</p>
<div class="highlight"><pre><span></span><code>/opt/smokeping/bin/smokeping --nodaemon
</code></pre></div>

<p>这样方便查看问题，也方便停止程序。真正使用还是作为服务启动。  </p>
<p>没有找到配置文件：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>/opt/smokeping/bin/smokeping --nodaemon
<span class="go">ERROR: loading smokeping configuration file /opt/smokeping/bin/../etc/config: 没有那个文件或目录</span>
<span class="gp">$ </span>
</code></pre></div>

<p>将配置文件复制一份，把后缀.dist去掉：</p>
<div class="highlight"><pre><span></span><code>cp /opt/smokeping/etc/config<span class="o">{</span>.dist,<span class="o">}</span>
</code></pre></div>

<p>然后配置文件里也有一些指向了.dist的文件，也把后缀去掉，去把文件复制一份改名：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>sed -n <span class="s1">&#39;s|\(.*\)\.dist|\1|p&#39;</span> /opt/smokeping/etc/config
<span class="go">smokemail = /opt/smokeping/etc/smokemail</span>
<span class="go">tmail = /opt/smokeping/etc/tmail</span>
<span class="go">template = /opt/smokeping/etc/basepage.html</span>
<span class="go">secrets=/opt/smokeping/etc/smokeping_secrets</span>
<span class="gp">$ </span>sed -i <span class="s1">&#39;s|\(.*\)\.dist|\1|&#39;</span> /opt/smokeping/etc/config
<span class="gp">$ </span>cp /opt/smokeping/etc/smokemail<span class="o">{</span>.dist,<span class="o">}</span>
<span class="gp">$ </span>cp /opt/smokeping/etc/tmail<span class="o">{</span>.dist,<span class="o">}</span>
<span class="gp">$ </span>cp /opt/smokeping/etc/basepage.html<span class="o">{</span>.dist,<span class="o">}</span>
<span class="gp">$ </span>cp /opt/smokeping/etc/smokeping_secrets<span class="o">{</span>.dist,<span class="o">}</span>
<span class="gp">$ </span>
</code></pre></div>

<p>这些文件都不用修改，至少目前都不用。  </p>
<p>还需要手动创建cache、data、var这3个文件夹：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>/opt/smokeping/bin/smokeping --nodaemon
<span class="go">ERROR: /opt/smokeping/bin/../etc/config, line 10: Directory &#39;/opt/smokeping/cache&#39; does not exist</span>
<span class="gp">$ </span>grep /opt/smokeping/cache /opt/smokeping/etc/config
<span class="go">imgcache = /opt/smokeping/cache</span>
<span class="gp">$ </span>mkdir /opt/smokeping/cache
<span class="gp">$ </span>/opt/smokeping/bin/smokeping --nodaemon
<span class="go">ERROR: /opt/smokeping/bin/../etc/config, line 12: Directory &#39;/opt/smokeping/data&#39; does not exist</span>
<span class="gp">$ </span>grep /opt/smokeping/data /opt/smokeping/etc/config
<span class="go">datadir  = /opt/smokeping/data</span>
<span class="gp">$ </span>mkdir /opt/smokeping/data
<span class="gp">$ </span>/opt/smokeping/bin/smokeping --nodaemon
<span class="go">ERROR: /opt/smokeping/bin/../etc/config, line 13: Directory &#39;/opt/smokeping/var&#39; does not exist</span>
<span class="gp">$ </span>grep /opt/smokeping/var /opt/smokeping/etc/config
<span class="go">piddir  = /opt/smokeping/var</span>
<span class="gp">$ </span>mkdir /opt/smokeping/var
<span class="gp">$ </span>
</code></pre></div>

<p>编译安装的fping的路径和配置文件中的不一样，这里修改配置文件：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>/opt/smokeping/bin/smokeping --nodaemon
<span class="go">ERROR: /opt/smokeping/bin/../etc/config, line 110: ERROR: FPing &#39;binary&#39; does not point to an executable</span>
<span class="gp">$ </span>grep fping /opt/smokeping/etc/config
<span class="go">binary = /usr/sbin/fping</span>
<span class="gp">$ </span>whereis fping
<span class="go">fping: /usr/local/sbin/fping</span>
<span class="gp">$ </span>sed -i <span class="s1">&#39;s|\(binary = \)/usr/sbin/fping|\1/usr/local/sbin/fping|&#39;</span> /opt/smokeping/etc/config
<span class="gp">$ </span>
</code></pre></div>

<p>确保文件smokeping_secrets的安全不能被别人访问，修改权限：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>/opt/smokeping/bin/smokeping --nodaemon
<span class="go">ERROR: /opt/smokeping/bin/../etc/config, line 113: File &#39;/opt/smokeping/etc/smokeping_secrets&#39; is world-readable or writable, refusing it</span>
<span class="gp">$ </span>chmod <span class="m">600</span> /opt/smokeping/etc/smokeping_secrets
<span class="gp">$ </span>
</code></pre></div>

<p>最后，终于能启动了：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>/opt/smokeping/bin/smokeping --nodaemon
<span class="go">WARNING: Hostname &#39;james.address&#39; does currently not resolve to an IPv6 or IPv4 address</span>
<span class="go">Smokeping version 2.007003 successfully launched.</span>
<span class="go">Not entering multiprocess mode for just a single probe.</span>
<span class="go">FPing: probing 1 targets with step 300 s and offset 116 s.</span>
</code></pre></div>

<p>有个WARNING，因为在Targets节里没有编辑监控的节点。加监控单独再讲。  </p>
<p>再写个服务启动的文件就完美了，见这章最后一小节<strong>小结：配置修改</strong>。  </p>
<h4 id="pei-zhi-web"><a class="toclink" href="#pei-zhi-web">配置Web</a></h4>
<p>打开防火墙：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>firewall-cmd --permanent --add-service<span class="o">=</span>http
<span class="go">success</span>
<span class="gp">$ </span>firewall-cmd --permanent --add-service<span class="o">=</span>https
<span class="go">success</span>
<span class="gp">$ </span>firewall-cmd --reload
<span class="go">success</span>
<span class="gp">$ </span>
</code></pre></div>

<p>添加httpd的配置文件：</p>
<div class="highlight"><pre><span></span><code>cat &gt; /etc/httpd/conf.d/smokeping.conf <span class="s">&lt;&lt; EOF</span>
<span class="s">&lt;Directory &quot;/opt/smokeping/htdocs&quot; &gt;</span>
<span class="s">  Require all granted</span>
<span class="s">&lt;/Directory&gt;</span>

<span class="s">&lt;Directory &quot;/opt/smokeping/cache&quot; &gt;</span>
<span class="s">  Require all granted</span>
<span class="s">&lt;/Directory&gt;</span>

<span class="s">ScriptAlias /smokeping/smokeping.fcgi /opt/smokeping/htdocs/smokeping.fcgi</span>
<span class="s">Alias       /smokeping/cache    /opt/smokeping/cache</span>
<span class="s">Alias       /smokeping          /opt/smokeping/htdocs</span>

<span class="s">RedirectMatch permanent &quot;^/smokeping/?$&quot; /smokeping/smokeping.fcgi</span>
<span class="s">EOF</span>

<span class="c1"># 文件夹/opt/smokeping/cache要给apache权限</span>
chown apache:apache /opt/smokeping/cache

<span class="c1"># fcgi文件直接改名，把后缀去掉</span>
mv /opt/smokeping/htdocs/smokeping.fcgi<span class="o">{</span>.dist,<span class="o">}</span>

<span class="c1"># 主服务的配置文件里再把首页改好</span>
sed -i <span class="se">\</span>
<span class="s1">&#39;s|\(cgiurl *= \)http://some.url/.*|\1http://localhost/smokeping/smokeping.cgi|&#39;</span> <span class="se">\</span>
/opt/smokeping/etc/config
</code></pre></div>

<p>在前台启动httpd，方便验证配置，下面两个命令都可以在前台运行：</p>
<div class="highlight"><pre><span></span><code><span class="c1"># DEBUG模式，也是在前台</span>
httpd -X
<span class="c1"># 前台启动</span>
httpd -D FOREGROUND
</code></pre></div>

<h4 id="xiao-jie-pei-zhi-bu-shu"><a class="toclink" href="#xiao-jie-pei-zhi-bu-shu">小结：配置部署</a></h4>
<p>上面有的乱，这里汇总一下。  </p>
<p>批量去掉后缀名：</p>
<div class="highlight"><pre><span></span><code><span class="gp">$ </span>ls /opt/smokeping/etc/*.dist <span class="p">|</span> awk -F <span class="s1">&#39;.dist&#39;</span> <span class="s1">&#39;{print $1}&#39;</span> <span class="p">|</span> xargs -t -I <span class="o">{}</span> cp <span class="o">{}</span>.dist <span class="o">{}</span>
<span class="go">cp /opt/smokeping/etc/basepage.html.dist /opt/smokeping/etc/basepage.html</span>
<span class="go">cp /opt/smokeping/etc/config.dist /opt/smokeping/etc/config</span>
<span class="go">cp /opt/smokeping/etc/smokemail.dist /opt/smokeping/etc/smokemail</span>
<span class="go">cp /opt/smokeping/etc/smokeping_secrets.dist /opt/smokeping/etc/smokeping_secrets</span>
<span class="go">cp /opt/smokeping/etc/tmail.dist /opt/smokeping/etc/tmail</span>
<span class="gp">$ </span>
</code></pre></div>

<p>这个命令比较复杂，单独列出来，参数-t可以不要，加上就是把实际执行的命令打印出来。  </p>
<p>剩余的命令如下：</p>
<div class="highlight"><pre><span></span><code><span class="c1">##########</span>
<span class="c1"># 主服务部分</span>
<span class="c1">##########</span>

<span class="c1"># 修改配置文件，去掉文件的 .dist 后缀</span>
sed -i <span class="s1">&#39;s|\(.*\)\.dist|\1|&#39;</span> /opt/smokeping/etc/config

<span class="c1"># 修改配置文件，修改fping的命令路径</span>
sed -i <span class="s1">&#39;s|\(binary = \)/usr/sbin/fping|\1/usr/local/sbin/fping|&#39;</span> /opt/smokeping/etc/config

<span class="c1"># 创建cache、data、var文件夹</span>
mkdir /opt/smokeping/<span class="o">{</span>cache,data,var<span class="o">}</span>

<span class="c1"># 修改文件smokeping_secrets为只读</span>
chmod <span class="m">600</span> /opt/smokeping/etc/smokeping_secrets


<span class="c1">##########</span>
<span class="c1"># Web部分</span>
<span class="c1">##########</span>

<span class="c1"># 打开防火墙</span>
firewall-cmd --permanent --add-service<span class="o">=</span>http
firewall-cmd --permanent --add-service<span class="o">=</span>https
firewall-cmd --reload
<span class="c1"># 添加httpd页面的配置文件</span>
cat &gt; /etc/httpd/conf.d/smokeping.conf <span class="s">&lt;&lt; EOF</span>
<span class="s">&lt;Directory &quot;/opt/smokeping/htdocs&quot; &gt;</span>
<span class="s">  Require all granted</span>
<span class="s">&lt;/Directory&gt;</span>

<span class="s">&lt;Directory &quot;/opt/smokeping/cache&quot; &gt;</span>
<span class="s">  Require all granted</span>
<span class="s">&lt;/Directory&gt;</span>

<span class="s">ScriptAlias /smokeping/smokeping.fcgi /opt/smokeping/htdocs/smokeping.fcgi</span>
<span class="s">Alias       /smokeping/cache    /opt/smokeping/cache</span>
<span class="s">Alias       /smokeping          /opt/smokeping/htdocs</span>

<span class="s">RedirectMatch permanent &quot;^/smokeping/?$&quot; /smokeping/smokeping.fcgi</span>
<span class="s">EOF</span>

<span class="c1"># 文件夹/opt/smokeping/cache要给apache权限</span>
chown apache:apache /opt/smokeping/cache

<span class="c1"># fcgi文件直接改名，把后缀去掉</span>
mv /opt/smokeping/htdocs/smokeping.fcgi<span class="o">{</span>.dist,<span class="o">}</span>

<span class="c1"># 主服务的配置文件里再把首页改好</span>
sed -i <span class="se">\</span>
<span class="s1">&#39;s|\(cgiurl *= \)http://some.url/.*|\1http://localhost/smokeping/smokeping.cgi|&#39;</span> <span class="se">\</span>
/opt/smokeping/etc/config
</code></pre></div>

<p>添加SmokePing的服务启动文件：</p>
<div class="highlight"><pre><span></span><code>cat &gt; /usr/lib/systemd/system/smokeping.service <span class="s">&lt;&lt; EOF</span>
<span class="s">[Unit]</span>
<span class="s">Description=Latency Logging and Graphing System</span>
<span class="s">After=syslog.target network.target</span>

<span class="s">[Service]</span>
<span class="s">ExecStart=/opt/smokeping/bin/smokeping --nodaemon</span>
<span class="s">ExecReload=/bin/kill -HUP $MAINPID</span>
<span class="s">StandardError=syslog</span>

<span class="s">[Install]</span>
<span class="s">WantedBy=multi-user.target</span>
<span class="s">EOF</span>

<span class="c1"># 修改service后，需要重载一下</span>
systemctl daemon-reload
</code></pre></div>

<p>启动服务：</p>
<div class="highlight"><pre><span></span><code>systemctl start httpd
systemctl <span class="nb">enable</span> httpd
systemctl start smokeping
systemctl <span class="nb">enable</span> smokeping
</code></pre></div>

<p>到此，系统运行起来了，但是还没有添加监控节点。继续看下一章。  </p>
<h3 id="tong-yong-she-zhi"><a class="toclink" href="#tong-yong-she-zhi">通用设置</a></h3>
<p>这里是一些通用的设置。另外配置生效可能需要重启服务，有的时候可能2个都要重启。  </p>
<p>页面显示的问题，就重启Web服务：</p>
<div class="highlight"><pre><span></span><code>systemctl restart httpd
</code></pre></div>

<p>如果添加了新的监控节点就重载配置：</p>
<div class="highlight"><pre><span></span><code>smokeping --reload
</code></pre></div>

<h4 id="pei-zhi-wen-jian-shuo-ming"><a class="toclink" href="#pei-zhi-wen-jian-shuo-ming">配置文件说明</a></h4>
<p>默认只有一个主配置文件<code>etc/config</code>，内部分成好几个部分：</p>
<ul>
<li>General节：个人信息和个性化描述，看着描述修改吧</li>
<li>Alerts节：告警相关的，不用就不改，略</li>
<li>Database节：保持默认，略</li>
<li>Presentation节：页面的模板配置，改下模板文件的路径，其他保持默认，略</li>
<li>Probes节：配置探针，默认只有FPing探针。这里只用FPing，保持默认，略</li>
<li>Slaves节：可以添加多个探点，这里只用主服务做探点，不深入了，略</li>
<li>Targets节：添加监控的节点，就这个讲一下</li>
</ul>
<h4 id="pei-zhi-targets"><a class="toclink" href="#pei-zhi-targets">配置Targets</a></h4>
<p>建议把监控的配置写一个单独的文件，这样调整监控节点的时候，不会误操作其他配置项。  </p>
<p>在主配置文件的最后加一行include的设置：</p>
<div class="highlight"><pre><span></span><code><span class="nb">echo</span> <span class="s1">&#39;@include dnsroot&#39;</span> &gt;&gt; /opt/smokeping/etc/config
</code></pre></div>

<p>这里表示导入dnsroot文件中的配置。  </p>
<p>编辑新的配置文件：</p>
<div class="highlight"><pre><span></span><code>cat &gt; /opt/smokeping/etc/dnsroot <span class="s">&lt;&lt; EOF</span>
<span class="s">+ dnsroot</span>
<span class="s">menu = Root Name Server</span>
<span class="s">title = Root Name Server System</span>

<span class="s">++ a</span>
<span class="s">menu = a.root-servers.net</span>
<span class="s">title = a.root-servers.net</span>
<span class="s">host = a.root-servers.net</span>
<span class="s">++ d</span>
<span class="s">menu = d.root-servers.net</span>
<span class="s">title = d.root-servers.net</span>
<span class="s">host = d.root-servers.net</span>
<span class="s">++ i</span>
<span class="s">menu = i.root-servers.net</span>
<span class="s">title = i.root-servers.net</span>
<span class="s">host = i.root-servers.net</span>
<span class="s">++ k</span>
<span class="s">menu = k.root-servers.net</span>
<span class="s">title = k.root-servers.net</span>
<span class="s">host = k.root-servers.net</span>
<span class="s">++ l</span>
<span class="s">menu = l.root-servers.net</span>
<span class="s">title = l.root-servers.net</span>
<span class="s">host = l.root-servers.net</span>
<span class="s">EOF</span>
</code></pre></div>

<p>修改后，两个服务都要重启。<br>
在+号后面的名称，会作为存储的rrd的文件名，不要有空格、中文还有点和斜杠这样的字符。<br>
这里使用了两个层级，可以有更多层级的，就是多个+号。没有host就是目录，有就是监控节点。<br>
menu是显示在左侧菜单栏里的内容。<br>
title是在中间页面最上面显示的标题内容。<br>
host是要监控的主机，域名或者是ip地址。<br>
如果用了中文，网页显示会有乱码。需要添加中文字符支持。  </p>
<h4 id="tian-jia-zhong-wen-zhi-chi"><a class="toclink" href="#tian-jia-zhong-wen-zhi-chi">添加中文支持</a></h4>
<p>安装中文字符集：</p>
<div class="highlight"><pre><span></span><code>yum install wqy-microhei-fonts
</code></pre></div>

<p>不一定非得是这个包，总之要有一个中文字符集。  </p>
<p>修改配置文件<code>/etc/smokeping/config</code>，在指定位置添加一行：</p>
<div class="highlight"><pre><span></span><code>*** Presentation ***

charset = utf-8  // 添加这一行
template = /etc/smokeping/basepage.html
</code></pre></div>
      </div>
      <div class="back-to-top">
        <a href="/">HOME</a>
        <a href="#top">TOP</a>
      </div>
    </article>
  </div>
<!-- end article -->
<!-- 页面往下滚动一段之后才会显示TOC -->
<script>
  window.onscroll = function() {
    var tocbox = document.getElementsByClassName('toc')[0];
    var osTop = document.documentElement.scrollTop || document.body.scrollTop;
    var osWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
    // console.log(osTop)
    if (osTop>300 && osWidth>865) {
      tocbox.style.display = "block"
    }
    if (osTop<300 || osWidth<865) {
      tocbox.style.display = "none"
    }
  }
</script>
                <footer>
                    <div class="icons">
                    </div>
                    <span id="busuanzi_container_page_pv" style="padding: 10px">本文阅读量<span id="busuanzi_value_page_pv"></span>次</span>
                    <span id="busuanzi_container_site_pv" style="padding: 10px">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
                    <span id="busuanzi_container_site_uv" style="padding: 10px">本站总访客数<span id="busuanzi_value_site_uv"></span>人</span>
                    <p>© <script>document.write(moment().format('YYYY'));</script> 749B</p>
                </footer>
        </div>
</body>
</html>